package framework.remote.post 
{
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	
	/**
	 * 处理URLRequest
	 * @author    henrylee
	 * 
	 */
	public class PostBase
	{
		protected var _mid:int = 6458002;							// id
		public static var KEY:String = "";							// KEY（本地调试线上时会用到）
		public static var GATE_WAY:String = ""						// 路径（本地调试线上时会用到）
		protected var _gateway:String = GATE_WAY;					// 服务器地址
		
		public function PostBase(gateway:String , mid:int) 
		{
			_gateway = gateway;
			_mid = mid;
		}
		
		public function loadUrlInOut(arr:Array):URLLoader
		{
			return loaderURL(arr);
		}
		
		protected function loaderURL(arr:Array):URLLoader
		{
			var _loader:URLLoader = new URLLoader();	
            var _request:URLRequest = new URLRequest(_gateway);
			var _variables:URLVariables = new URLVariables();
            _request.data = _variables;
            _request.method = URLRequestMethod.POST;
			_variables.win_param = genParam(arr);
			if (GlobalConfig.lanVersion == 1)
			{
				_variables.mgid = GlobalConfig.mgid;
			}
			_loader.load(_request);
			return _loader;
		}
		
		
		/**
		 * 生成完整的带签名的参数
		 * @param param
		 */
		protected function genParam(param:Array):String
		{
			var ret:Object = new Object();
			ret["mid"] = _mid;
			ret["sitekey"] = GlobalConfig.sitekey;
			ret['group'] = '';
			ret['mnick'] = '';
			ret["key"] = KEY;
			ret['method'] = param[0];
			ret['param'] = param[1];
			return JSON.encode(ret);
		}
		
		
		//protected function Keyexpired(str:String):void
		//{
			//if (str == "false")
			//{
				//Tooltip.instance.showSystemInfor(LangManager.getLang.getLangByStr("ymgqsxym"), LangManager.getLang.getLangByStr("reloadpages"), 1, 1);
			//}
		//}
	}
}